/*  
*   This file is a part of Neutrino - a lightweight UI library accelerated with OpenGL
*   Copyright (C) 2023 bsolos
*
*   This program is free software: you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation, either version 3 of the License, or
*   (at your option) any later version.
*
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*   GNU General Public License for more details.
*
*   You should have received a copy of the GNU General Public License
*   along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

#include <glad/glad.h>

#define NO_UNDEF_UNIFORM_METHOD_GENERATOR
#include <neutrino.hpp>

using namespace neutrino;

// TODO: implement
shader::shader(render_context *ctx, char *vertex_src, char *fragment_src) 
    : ctx(ctx) {
    
}

shader::~shader() {}

void shader::use() {
    glUseProgram(program);
}

GLint shader::uniform_location(std::string uniform) { 
    if (uniform_locations.contains(uniform)) {
        return uniform_locations[uniform];
    } else {
        GLint location = glGetUniformLocation(program, uniform.c_str());
        uniform_locations[uniform] = location;
        return location;
    }
}

// uniform method implementations
#undef UNIFORM_METHOD_BODY
#define UNIFORM_METHOD_BODY(argc, glsuff) { glUniform##argc##glsuff(uniform_location(uniform), GEN_ARGS##argc()); }
UNIFORM_METHODS(shader::)
